<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
    <title>ShellCheck: SC1010 – Use semicolon or linefeed before `done` (or quote to make it literal).</title>
    <link rel="stylesheet" href="css/bootstrap.min.css" />
  </head>
  <body style="margin-left: auto; margin-right: auto; max-width: 800px">
    <h1>SC1010 – ShellCheck Wiki</h1>
    <a href="https://github.com/koalaman/shellcheck/wiki/SC1010">See this page on GitHub</a>
    <p style="display: none"><a href="index.html">Sitemap</a></p>
    <hr />
    <h2
id="use-semicolon-or-linefeed-before-done-or-quote-to-make-it-literal">Use
semicolon or linefeed before <code>done</code> (or quote to make it
literal).</h2>
<p>(or <code>do</code> <code>then</code>, <code>fi</code>,
<code>esac</code>)</p>
<h3 id="problematic-code">Problematic code:</h3>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="SC1010.html#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> f <span class="kw">in</span> <span class="pp">*</span><span class="kw">;</span> <span class="cf">do</span> <span class="bu">echo</span> <span class="st">&quot;</span><span class="va">$f</span><span class="st">&quot;</span> done</span></code></pre></div>
<p>or</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="SC1010.html#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="va">$f</span> is done</span></code></pre></div>
<h3 id="correct-code">Correct code:</h3>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="SC1010.html#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> f <span class="kw">in</span> <span class="pp">*</span><span class="kw">;</span> <span class="cf">do</span> <span class="bu">echo</span> <span class="st">&quot;</span><span class="va">$f</span><span class="st">&quot;</span><span class="kw">;</span> <span class="cf">done</span></span></code></pre></div>
<p>or</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="SC1010.html#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="bu">echo</span> <span class="st">&quot;</span><span class="va">$f</span><span class="st"> is done&quot;</span></span></code></pre></div>
<h3 id="rationale">Rationale:</h3>
<p>ShellCheck found a keyword like <code>done</code>, <code>then</code>,
<code>fi</code>, <code>esac</code>, etc used as the argument of a
command. This means that the shell will interpret it as a literal string
rather than a shell keyword. To be interpreted as a keyword, it must be
the first word in the line (i.e. after <code>;</code>,
<code>&amp;</code> or a linefeed).</p>
<p>In the example, <code>echo "$f" done</code> is the same as
<code>echo "$f" "done"</code>, and the <code>done</code> does not
terminate the loop. This is fixed by terminating the <code>echo</code>
command with a <code>;</code> so that the <code>done</code> is the first
word in the next line.</p>
<h3 id="exceptions">Exceptions</h3>
<p>If you're intentionally using <code>done</code> as a literal, you can
quote it to make this clear to ShellCheck (and also human readers), e.g.
instead of <code>echo Task is done</code>, use
<code>echo "Task is done"</code>. This makes no difference to the shell,
but it will silence this warning.</p>
    <hr />
    <p style='font-size: 80%'><a href="../index.html">ShellCheck</a> is a static analysis tool for shell scripts. This page is part of its documentation.</p>
  </body>
</html>


